/*
 * @Author: zhouwei wei.zhou@flip.fun
 * @Date: 2024-04-08 11:08:31
 * @LastEditors: zhouwei wei.zhou@flip.fun
 * @LastEditTime: 2024-04-08 17:40:30
 * @FilePath: /50/手撕系列/curry.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 *
 * @param {Function} fn
 * @returns
 */
function curry() {
	const fn = Array.prototype.shift.call(arguments)
	let argsArray = Array.prototype.slice.call(arguments)
	const length = fn.length
	return function () {
		const args = Array.prototype.slice.call(arguments)
		argsArray = argsArray.concat(args)
		if (argsArray.length === length) {
			return fn.apply(this, argsArray)
		} else {
			return curry(fn, ...argsArray)
		}
	}
}
function esCurry(fn, ...args) {
	return args.length === fn.length ? fn.apply(this, args) : (...argsArray) => esCurry(fn, ...argsArray.concat(args))
}
const curryFn = curry((a, b, c) => a + b + c, 1)
console.log(curryFn(2, 3))
